package com.ruoyi.mongo.service;

import com.ruoyi.mongo.word.entity.WordCheckNewRecord;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class MongoListService {

    private final MongoCommonService mongoCommonService;

    public MongoListService(MongoCommonService mongoCommonService) {
        this.mongoCommonService = mongoCommonService;
    }

    public <T> List<?> getAllListData(T t, String collectionName, String unit, String book) {
        Query query = MongoService.getDataCommon(unit, book);
        return mongoCommonService.getList(t, query, collectionName);
    }

    /**
     * 只限初中测试
     * 兼容旧列表
     * */
    public List<?> getAllListData(String collectionName, String practice){
        Query query = new Query();
        if (practice != null && !practice.isEmpty()){
            Criteria criteria = Criteria.where(MongoConstants.MONGO_PRACTICE).is(practice);
            query.addCriteria(criteria);
        }
        List<?> list;
        list = mongoCommonService.getList(new WordCheckNewRecord(), query,collectionName);
        return list;
    }

    /**
     * 只限初中测试
     * 兼容旧列表
     * */
    public List<?> getAllListData(String collectionName, String practice, int way){
        Query query = new Query();
        if (practice != null && !practice.isEmpty()){
            Criteria criteria = Criteria.where(MongoConstants.MONGO_PRACTICE).is(practice);
            query.addCriteria(criteria);
        }
        List<?> list = null;
        if (way == 2 || way == 3) {
            list = mongoCommonService.getList(new WordCheckNewRecord(), query,collectionName);
        }
        return list;
    }
}
